package think.in.java.concurrency.PractiseOneMoreTime;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Repeat Exercise 2 using the different types of executors shown in this section
 */
public class Exec4ForExecutor implements Runnable {
    private int iteratorTimes =0;

    public Exec4ForExecutor(Integer iteratorTimes){
        this.iteratorTimes = iteratorTimes;
    }

    @Override
    public void run() {
        IteratorFibonacci iteratorFibonacci = new IteratorFibonacci(iteratorTimes);
        for(Integer result : iteratorFibonacci){
            System.out.println(Thread.currentThread().getName()+":"+ result);
            Thread.yield();
        }
    }

    public static void main(String[] args){
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for(int i=0; i <3 ; i++){
            executorService.execute(new Exec4ForExecutor(20));
        }
        executorService.shutdown();
    }
}
